package system

import (
	"errors"
	"k8s-admin/dao/system"
	"k8s-admin/global"
	"k8s-admin/models"
)

type InterfaceService interface {
	CreateService(username, password, authkey, ipaddress, ServiceName, ServiceVersion string, status, port int) error
	UpdateService(property_number, username, password, authkey, ipaddress, ServiceName, ServiceVersion string, status, port int) error
	List() (*models.ListReq, error)
	Delete(propertynumber string) error
}
type serviceInfo struct{}

func NewServiceInfo() InterfaceService {
	return &serviceInfo{}
}

func (r *serviceInfo) CreateService(username, password, authkey, ipaddress, ServiceName, ServiceVersion string, status, port int) error {
	err := system.NewServicesInterface().CreateService(username, password, authkey, ipaddress, ServiceName, ServiceVersion, status, port)
	if err != nil {
		global.TPLogger.Error(err)
		return errors.New("创建失败")
	} else {
		return nil
	}

}

func (r *serviceInfo) List() (*models.ListReq, error) {
	list, err := system.NewServicesInterface().List()
	if err != nil {
		global.TPLogger.Error(err)
		return nil, errors.New("没有数据")
	} else {
		return list, nil
	}
}
func (r *serviceInfo) Delete(propertynumber string) error {
	err := system.NewServicesInterface().Delete(propertynumber)
	if err != nil {
		global.TPLogger.Error(err)
		return errors.New("删除失败")
	} else {
		return nil
	}
}

func (r *serviceInfo) UpdateService(property_number, username, password, authkey, ipaddress, ServiceName, ServiceVersion string, status, port int) error {
	err := system.NewServicesInterface().UpdateService(property_number, username, password, authkey, ipaddress, ServiceName, ServiceVersion, status, port)
	if err != nil {
		global.TPLogger.Error(err)
		return errors.New("更新失败")
	} else {
		return nil
	}
}
